import 'package:flutter/cupertino.dart';
import './val_data_base_constant.dart';
import './val_data_base_core.dart';
import './val_data_base_entity.dart';


class ValDataBaseManager {
  ValDataBaseManager._init();

  static final ValDataBaseManager _instance = ValDataBaseManager._init();

  factory ValDataBaseManager() => _instance;

  /// 初始化数据库
  Future<void> setup() async {
    await ValDataBaseCore().setup();
  }

  /// 获取实体
  static ValDataBaseEntity getEntity({
    required String dbTableName,
    required String primaryKey,
    required Map<String, ValDataBaseQueryEnum> queryKeys,
  }){
   return ValDataBaseEntity(dbTableName: dbTableName,
       primaryKey: primaryKey,
       queryKeys: queryKeys);
  }

  static Future<void> openDb() async {
    await  ValDataBaseCore.openDb();
  }

  /// 关闭数据库
  static void closeDataBase() {
    ValDataBaseCore.closeDb();
  }

  /// 删表
  static Future<void> deleteTable(String dbName) async {
    await  ValDataBaseCore.deleteTable(dbName);
  }

  /// 清空
  static Future<void> cleanTable(String dbName , ValueChanged<bool> completion) async {
    await ValDataBaseCore.cleanTable(dbName ,completion );
  }
}


